package com.wsc.producer.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 发送消息
 */
//启动绑定
@EnableBinding(Barista.class)
@Component
public class RabbitSender {

    @Autowired
    private Barista barista;

    /**
     * 发送消息
     * @return
     */
    public String sendMsg(Object message, Map<String,Object> properties){
        MessageHeaders mhs = new MessageHeaders(properties);
        Message msg = MessageBuilder.createMessage(message, mhs);
        boolean sendStatus = barista.logOutput().send(msg);
        System.err.println("-----------------------------");
        System.err.println("发送消息 :"+msg+",发送状态："+sendStatus);
        return null;
    }
}
